package com.lagou.conntroller;/**
 * Created by IntelliJ IDEA.
 * User: Yangdx.
 * Date: 2020/7/26.
 * Time: 0:58.
 * Tags: Code, we are serious.
 */

import com.lagou.model.EmailService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author
 * @create 2020-07-26 0:58
 **/
@RestController
@RequestMapping("/email")
@RefreshScope
public class EmailController {
    @Resource
    private EmailService emailService;

    @Value("${config.email.templates.checkcode.title}")
    private String mailTitle;

    @Value("${config.email.templates.checkcode.content}")
    private String mailContent;

    @GetMapping("/{email}/{code}")
    public Boolean sendMail(@PathVariable("email") String email,
                            @PathVariable("code") String checkCode) {
        String message = String.format(mailContent, checkCode);
        return emailService.sendEmail(email, mailTitle, message);
    }
}
